function rename(name) {
  var newName = name;
  if (documents.length > 0) {
    var activeDocument = app.activeDocument;
    var elementsSelected = activeDocument.selection;
    if (elementsSelected.length > 0) {
      for (i = 0; i < elementsSelected.length; i++) {
        var targetItem = elementsSelected[i];
        if (targetItem.typename == "TextFrame") {
          targetItem.contents = newName;
        }
        targetItem.name = newName;
        targetItem.selected = false;
      }
    } else {
      alert("请先选中一个物体!");
    }
  } else {
    alert("请先打开一个文档!");
  }
}
